package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class JDBCDemo8 {
    public static void main(String[] args) {
        try(Connection connection = DBUtil.getConnection()){
            Statement statement = connection.createStatement();
            String sql = "select count(*) count, c.name\n" +
                    "from student s\n" +
                    "join class c on s.class_id = c.id \n" +
                    "group by c.name";
            ResultSet rs = statement.executeQuery(sql);
            System.out.println("班级人数—班级名");
            while(rs.next()){
                int count = rs.getInt("count");
                String cName = rs.getString("c.name");
                System.out.println(count + " , " + cName);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
